<?php

namespace App\Providers;

use App\Observers\WechatLinkObserver;
use App\WechatLink;
use EasyWeChat\MiniProgram\Application as MiniProgram;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Overtrue\EasySms\EasySms;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        WechatLink::observe(WechatLinkObserver::class);
        Schema::defaultStringLength(191);
        $this->app->singleton('sms', function () {

            $config = [
                // HTTP 请求的超时时间（秒）
                'timeout' => 5.0,

                // 默认发送配置
                'default' => [
                    // 网关调用策略，默认：顺序调用
                    'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

                    // 默认可用的发送网关
                    'gateways' => [
                        'aliyun',
                    ],
                ],
                // 可用的网关配置
                'gateways' => [
                    'errorlog' => [
                        'file' => storage_path('/logs/easy-sms.log')
                    ],

                    'aliyun' => [
                        'access_key_id' => config('aliyun_sms.accessKeyId'),
                        'access_key_secret' => config('aliyun_sms.accessKeySecret'),
                        'sign_name' => config('aliyun_sms.signName'),
                    ],
                    //...
                ],
            ];

            return   new EasySms($config);
        });
        $this->app->singleton("mini.agent", function ($laravelApp) {
            $app = new MiniProgram(config('miniAgent'));
            return $app;
        });
        /*   \DB::listen(function ($query) {
               $sql=$query->sql;
               $bindings=$query->bindings;
               $time=$query->time;

               \Log::debug(json_encode($query));
               \Log::debug(var_export(compact('sql','bindings','time'),true));

           });*/
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
    }
}
